package net.csdn.business.common.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author likun
 * @date 2022/6/14 17:31
 */
public interface IssueEnum {
    /**
     * 排序状态
     */
    List<StatusEnum> ISSUE_COUNT_STATUS = Lists.newArrayList(StatusEnum.CLOSE, StatusEnum.OPEN);

    @Getter
    @AllArgsConstructor
    enum PrivacyEnum {
        /**
         * 隐私状态
         */
        NO(0),
        YES(1),
        ;
        final int code;

    }

    @Getter
    @AllArgsConstructor
    enum LockEnum {
        /**
         * 隐私状态
         */
        NO(0),
        YES(1),
        ;
        final int code;

        public static LockEnum ofCode(int code) {
            for (LockEnum pinEnum : LockEnum.values()) {
                if (pinEnum.code == code) {
                    return pinEnum;
                }
            }
            throw new IllegalArgumentException("IssueEnum#LockEnum param error");
        }
    }

    @Getter
    @AllArgsConstructor
    enum PinEnum {
        /**
         * 状态
         */
        UN_PIN(0),
        PIN(1),
        ;

        final int code;

        public static PinEnum ofCode(int code) {
            for (PinEnum pinEnum : PinEnum.values()) {
                if (pinEnum.code == code) {
                    return pinEnum;
                }
            }
            throw new IllegalArgumentException("IssueEnum#PinEnum param error");
        }
    }

    @Getter
    @AllArgsConstructor
    enum MoveEnum {
        /**
         * 状态
         */
        UN_MOVE(0),
        MOVE(1),
        ;

        final int code;
    }

    @Getter
    @AllArgsConstructor
    enum LabelEnum {
        /**
         * 是否增加label
         */
        NO(0),
        YES(1),
        ;

        final Integer code;
    }

    @Getter
    @AllArgsConstructor
    enum StatusEnum {
        /**
         * 状态
         */
        OPEN(1, "open", ResourceEnum.KeyEnum.ISSUE_OPEN_COUNT),
        CLOSE(2, "closed", ResourceEnum.KeyEnum.ISSUE_CLOSE_COUNT),
        REJECTED(2, "rejected", ResourceEnum.KeyEnum.ISSUE_CLOSE_COUNT),
        PROGRESSING(1, "progressing", ResourceEnum.KeyEnum.ISSUE_OPEN_COUNT),
        ;

        final int code;
        final String key;
        final ResourceEnum.KeyEnum keyEnum;

        public static StatusEnum ofCode(int code) {
            for (StatusEnum statusEnum : StatusEnum.values()) {
                if (statusEnum.code == code) {
                    return statusEnum;
                }
            }
            throw new IllegalArgumentException("IssueEnum#StatusEnum param error");
        }

        public static StatusEnum ofKey(String key) {
            for (StatusEnum statusEnum : StatusEnum.values()) {
                if (statusEnum.key.equals(key)) {
                    return statusEnum;
                }
            }
            throw new IllegalArgumentException("IssueEnum#StatusEnum param error");
        }

        public static StatusEnum ofKeyDefault(String key) {
            for (StatusEnum statusEnum : StatusEnum.values()) {
                if (statusEnum.key.equals(key)) {
                    return statusEnum;
                }
            }
            return StatusEnum.OPEN;
        }

        public static StatusEnum ofCodeNull(Integer code) {
            if (null == code) {
                return null;
            }
            for (StatusEnum statusEnum : StatusEnum.values()) {
                if (statusEnum.code == code) {
                    return statusEnum;
                }
            }
            return StatusEnum.CLOSE;
        }
    }

    @Getter
    @AllArgsConstructor
    enum StatusReasonEnum {
        /**
         * 状态
         */
        CHECKED(1, "完成关闭"),
        NOT_PLANNED(2, "未按计划关闭"),
        /**
         * 通过仓库关联关闭issue(未落库，区分issue change event)
         */
        MR_CLOSE(3, "完成关联MR关闭"),
        ;

        final int code;
        final String desc;
    }

    @Getter
    @AllArgsConstructor
    enum MigrateStatusReasonEnum {
        /**
         * 状态
         */
        CHECKED(1, "已完成"),
        NOT_PLANNED(2, "待办的"),
        NOT_PLANNED_NEW(2, "新建"),
        CANCLLED(1, "已取消"),
        /**
         * 通过仓库关联关闭issue(未落库，区分issue change event)
         */
        MR_CLOSE(3, "完成关联MR关闭"),
        ;

        final int code;
        final String desc;


        public static MigrateStatusReasonEnum ofKey(String key) {
            for (MigrateStatusReasonEnum statusEnum : MigrateStatusReasonEnum.values()) {
                if (statusEnum.desc.equals(key)) {
                    return statusEnum;
                }
            }
            return MigrateStatusReasonEnum.CHECKED;
        }
    }

    @Getter
    @AllArgsConstructor
    enum OrderByEnum {
        /**
         * 排序规则
         */
        RECENTLY_UPDATE("recent_update", "updated_date", false,1),
        EARLIER_UPDATE("earlier_update", "updated_date", true,2),
        RECENTLY_CREATE("recent_create", "created_date", false,3),
        EARLIER_CREATE("earlier_create", "created_date", true,4),
        ;
        final String code;
        final String field;
        final Boolean order;
        final Integer value;

        public static OrderByEnum ofCode(String code) throws IllegalArgumentException {
            for (OrderByEnum order : OrderByEnum.values()) {
                if (order.code.equalsIgnoreCase(code)) {
                    return order;
                }
            }
            throw new IllegalArgumentException("IssueEnum#OrderByEnum param error");
        }
    }

    @Getter
    @AllArgsConstructor
    enum QueryTypeEnum {
        /**
         * 与我相关
         */
        ABOUT("about", "uid", "与我相关", true),
        /**
         * 指派给我
         */
        ASSIGN("assign_user", "assign_user", "指派给我", true),
        ;
        final String code;
        final String field;
        final String desc;
        final Boolean needUid;

        public static QueryTypeEnum ofCode(String code) throws IllegalArgumentException {
            for (QueryTypeEnum queryType : QueryTypeEnum.values()) {
                if (queryType.code.equalsIgnoreCase(code)) {
                    return queryType;
                }
            }
            throw new IllegalArgumentException("IssueEnum#QueryTypeEnum param error");
        }
    }



    /**
     * issue优先级枚举
     */
    @Getter
    @AllArgsConstructor
    enum PriorityEnum {
        /**
         * 优先级
         */
        NOT_SPECIFIED(0, "未指定","#B0B0B0"),
        UN_IMPORTANT(10, "不重要","#73E06F"),
        SECONDARY(20, "次要","#008AFF"),
        PRIMARY(30, "主要","#FF8F00"),
        IMPORTANT(40, "严重","#EF0016"),
        ;

        final int code;
        final String name;
        final String color;

        public static PriorityEnum ofCode(int code) {
            for (PriorityEnum priorityEnum : PriorityEnum.values()) {
                if (priorityEnum.code == code) {
                    return priorityEnum;
                }
            }
            throw new IllegalArgumentException("IssueEnum#PriorityEnum param error");
        }
    }

}
